package org.mclll.xwangplugin.questTracking.command;

import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mclll.xwangplugin.MclllCustom;
import org.mclll.xwangplugin.questTracking.gui.BossShopMenuController;
import org.mclll.xwangplugin.questTracking.listener.QuestListener;
import org.mclll.xwangplugin.town.config.TownContext;

import java.util.List;

/**
 * @author: geduo
 * @date: 2023/10/16 14:48
 */
public class QuestTrackingCommand implements TabExecutor {

    private MclllCustom plugin;

    public QuestTrackingCommand(MclllCustom plugin) {
        this.plugin = plugin;
    }
    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(TownContext.ONLY_PLAYER_COMMAND);
            return false;
        }
        if (args.length < 1 || StringUtils.isBlank(args[0])) {
            BossShopMenuController.openQuestTrackingMenu((Player) sender, plugin);
            return true;
        } else {
            switch (args.length) {
                case 1:
                    QuestListener.trackingOther((Player) sender,  args[0]);
                    return true;
                default:
                    QuestListener.trackingOther((Player) sender, String.join(" ", args));
            }
        }
        return false;
    }

    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        return null;
    }
}
